package com.zline.foodraise.util;

import android.content.Context;
import android.os.Build;
import android.util.DisplayMetrics;
import android.view.WindowManager;

import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootContext;

/**
 * Created by heshantao on 15/6/25.
 */
@EBean
public class DeviceUtil {
    private static final String LOG_TAG = DeviceUtil.class.getSimpleName();
    @RootContext
    Context context;

    public int getDeviceVersion() {
        return Build.VERSION.SDK_INT;
    }

    /**
     * 获取屏幕宽度
     */
    public static int getDeviceWidth(Context cxt) {
        try {
            DisplayMetrics displayMetrics = new DisplayMetrics();
            WindowManager windowManager = (WindowManager)
                    cxt.getSystemService(Context.WINDOW_SERVICE);
            windowManager.getDefaultDisplay().getMetrics(displayMetrics);
            int width = displayMetrics.widthPixels;
            return width;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }


    /**
     * 获取屏幕高度
     */
    public static int getDeviceHeight(Context cxt) {
        try {
            DisplayMetrics displayMetrics = new DisplayMetrics();
            WindowManager windowManager = (WindowManager)
                    cxt.getSystemService(Context.WINDOW_SERVICE);
            windowManager.getDefaultDisplay().getMetrics(displayMetrics);
            int height = displayMetrics.heightPixels;
            return height;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }


    /**
     * 获取屏幕密度
     */
    public static float getDeviceDesity(Context cxt) {
        try {
            DisplayMetrics displayMetrics = new DisplayMetrics();
            WindowManager windowManager = (WindowManager)
                    cxt.getSystemService(Context.WINDOW_SERVICE);
            windowManager.getDefaultDisplay().getMetrics(displayMetrics);
            float desity = displayMetrics.density;
            return desity;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

}
